﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <div id="settings" class="easyui-layout animated fadeInRight" data-options="fit:true">
        <div data-options="region:'center',border:false">
            <div class="datagrid-toolbar">
                <table cellspacing="0" cellpadding="0">
                    <tbody>
                        <tr>
                            <td><a href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain" id="btnSaveSettings"><span class="l-btn-left"><span class="l-btn-text"><i class="fa fa-save"></i> 保存</span></span></a></td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="easyui-panel" data-options="fit:true" style="border:0; padding:20px;">
                <form id="GeneralForm" class="easyui-form" data-options="novalidate:true">
                    <h3>基本设置</h3>
                    <table cellpadding="5">
                        @if (ViewBag.TenantId == null)
                        {
                            <tr>
                                <th>系统名称</th>
                                <td><input class="easyui-textbox" type="text" name="appName" data-options="required:true" style="width:300px;" /></td>
                            </tr>
                        }
                        <tr>
                            <th>分页大小</th>
                            <td><input class="easyui-numberspinner" type="text" name="appPageSize" data-options="required:true,min:10" /> <span class="faq"><i class="fa fa-question-circle"></i> 后台数据列表分页大小，默认为每页10条记录</span></td>
                        </tr>
                    </table>
                </form>
                @if (!ViewBag.IsMultiTenancyEnabled)
                {
                    <br />
                    <form id="EmailForm" class="easyui-form" data-options="novalidate:true">
                        <h3>邮件发送</h3>
                        <table cellpadding="5">
                            <tr>
                                <th>默认发送邮箱地址</th>
                                <td><input type="email" name="defaultFromAddress" class="easyui-textbox" data-options="required:true" style="width:300px;" /></td>
                            </tr>
                            <tr>
                                <th>默认发送人名字</th>
                                <td><input type="text" name="defaultFromDisplayName" class="easyui-textbox" data-options="required:true" /></td>
                            </tr>
                            <tr>
                                <th>SMTP服务器</th>
                                <td><input type="text" name="smtpHost" class="easyui-textbox" data-options="required:true" style="width:300px;" /></td>
                            </tr>
                            <tr>
                                <th>SMTP端口</th>
                                <td><input type="text" name="smtpPort" class="easyui-numberspinner" data-options="required:true,min:0" /></td>
                            </tr>
                            <tr>
                                <th>使用SSL</th>
                                <td><input type="checkbox" name="smtpEnableSsl" value="true" /></td>
                            </tr>
                            <tr>
                                <th>默认身份验证</th>
                                <td><input type="checkbox" name="smtpUseDefaultCredentials" value="true" /></td>
                            </tr>
                            <tr>
                                <th>域名</th>
                                <td><input type="text" name="smtpDomain" class="easyui-textbox" data-options="required:true" style="width:300px;" /></td>
                            </tr>
                            <tr>
                                <th>用户名</th>
                                <td><input type="text" name="smtpUserName" class="easyui-textbox" data-options="required:true" /></td>
                            </tr>
                            <tr>
                                <th>密码</th>
                                <td><input type="text" name="smtpPassword" class="easyui-textbox" data-options="required:true" /></td>
                            </tr>
                        </table>
                    </form>
                }
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var generalForm = $('#GeneralForm'),
                emailForm = $('#EmailForm'),
                _serviceSettings = abp.services.app.settings;

            $('#btnSaveSettings').click(function () {
                _serviceSettings.updateAllSettings({
                    general: generalForm.serializeFormToObject(),
                    email: emailForm.serializeFormToObject()
                }, {
                    beforeSend: function () {
                        return generalForm.form('enableValidation').form('validate');
                    }
                })
                    .done(function () {
                        showToast('设置已经成功保存');
                    });
            });

            var loadSettings = function () {
                _serviceSettings.getAllSettings({})
                    .done(function (data) {
                        if(emailForm) emailForm.form('load', data.email);
                        generalForm.form('load', data.general);
                    });
            }

            loadSettings();
        });
    </script>
</body>
</html>
